package com.example.qing.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.qing.pojo.Logs;
import com.example.qing.pojo.Result;
import com.example.qing.service.LogService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/logs")
public class LogController {

    @Resource
    LogService logService;



    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id){
        logService.removeById(id);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestBody List<Integer> ids){
        log.info("批量删除");
        logService.removeByIds(ids);
        return Result.success();
    }



    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){

        Logs logs=logService.getById(id);
        return Result.success(logs);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Logs logs){
        logService.updateById(logs);
        return Result.success();
    }

    @GetMapping("/selectByPage")
    public Result list(@RequestParam Integer pageNum,
                       @RequestParam Integer pageSize,
                       @RequestParam String  module){
        log.info("分页查询");
        QueryWrapper<Logs>queryWrapper=new QueryWrapper<Logs>().orderByDesc("id");
        queryWrapper.like(StrUtil.isNotBlank(module),"module",module);
        Page<Logs>page=logService.page(new Page<>(pageNum,pageSize),queryWrapper);
        return Result.success(page);
    }

}